package net.mcreator.infinite_storage;

import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.ByteBufUtils;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.Minecraft;

import java.util.logging.Handler;

import io.netty.buffer.ByteBuf;

public class EntityDataMsgClientInfiniteStorageMod implements IMessage {
	private NBTTagCompound entityData;
	public EntityDataMsgClientInfiniteStorageMod() {
	}

	public EntityDataMsgClientInfiniteStorageMod(NBTTagCompound entityData) {
		this.entityData = entityData;
	}

	@Override
	public void fromBytes(ByteBuf buf) {
		entityData = new NBTTagCompound();
		entityData = ByteBufUtils.readTag(buf);
	}

	@Override
	public void toBytes(ByteBuf buf) {
		ByteBufUtils.writeTag(buf, entityData);
	}
	public static class Handler implements IMessageHandler<EntityDataMsgClientInfiniteStorageMod, IMessage> {
		@Override
		public IMessage onMessage(EntityDataMsgClientInfiniteStorageMod message, MessageContext ctx) {
			Minecraft.getMinecraft().addScheduledTask(() -> {
				EntityPlayerSP player = Minecraft.getMinecraft().player;
				if (player != null && player.world != null) {
					player.getEntityData().setTag("InfiniteBag", message.entityData.getCompoundTag("InfiniteBag"));
				}
			});
			return null;
		}
	}
}
